Imports System.Windows.Forms
Imports Vintasoft.Imaging
Imports Vintasoft.Pdf

Namespace Pdf
	Public Partial Class PdfRenderingSettingsForm
		Inherits Form

		#Region "Constructor"

		Public Sub New(settings As PdfRenderingSettings)
			InitializeComponent()

			btOK.Focus()

			_renderingSettings = settings

			renderingMode.Items.Add(PdfRenderingMode.HighSpeed)
			renderingMode.Items.Add(PdfRenderingMode.Normal)
			renderingMode.Items.Add(PdfRenderingMode.HighQuality)
			renderingMode.SelectedItem = _renderingSettings.RenderingMode

			If settings.Resolution.IsEmpty() Then
				dpiDefault.Checked = True
			Else
				dpiDefault.Checked = False
				horizontalResolution.Value = CInt(settings.Resolution.Horizontal)
				verticalResolution.Value = CInt(settings.Resolution.Vertical)
			End If
			drawAnnotations.Checked = _renderingSettings.DrawPdfAnnotations OrElse _renderingSettings.DrawVintasoftAnnotations
			cacheResources.Checked = _renderingSettings.CacheResources
			cropPageAtCropBox.Checked = _renderingSettings.UseCropBox
			useRotatePropertyCheckBox.Checked = _renderingSettings.UsePageRotateProperty
		End Sub

		#End Region



		#Region "Properties"

		Private _renderingSettings As PdfRenderingSettings
		Public ReadOnly Property RenderingSettings() As PdfRenderingSettings
			Get
				Return _renderingSettings
			End Get
		End Property

		#End Region



		#Region "Methods"

		Private Sub btOK_Click(sender As Object, e As EventArgs)
			If dpiDefault.Checked Then
				_renderingSettings.Resolution = Resolution.Empty
			Else
				_renderingSettings.Resolution = New Resolution(CSng(horizontalResolution.Value), CSng(verticalResolution.Value))
			End If
			_renderingSettings.RenderingMode = DirectCast(renderingMode.SelectedItem, PdfRenderingMode)
			_renderingSettings.DrawPdfAnnotations = drawAnnotations.Checked
			_renderingSettings.DrawVintasoftAnnotations = drawAnnotations.Checked
			_renderingSettings.CacheResources = cacheResources.Checked
			_renderingSettings.UseCropBox = cropPageAtCropBox.Checked
			_renderingSettings.UsePageRotateProperty = useRotatePropertyCheckBox.Checked
			DialogResult = DialogResult.OK
		End Sub

		Private Sub dpiDefault_CheckedChanged(sender As Object, e As EventArgs)
			horizontalResolution.Enabled = Not dpiDefault.Checked
			verticalResolution.Enabled = Not dpiDefault.Checked
		End Sub

		Private Sub btCancel_Click(sender As Object, e As EventArgs)
			DialogResult = DialogResult.Cancel
		End Sub

		Private Sub horizontalResolution_ValueChanged(sender As Object, e As EventArgs)
			verticalResolution.Value = horizontalResolution.Value
		End Sub

		#End Region

	End Class
End Namespace
